<template>
  <div class="app-container">
    <wms-form v-model:query-params="queryParams" :form-list="formList" @query="getList" @export="handleExport">
      <file-upload v-model="fileList" :file-type="['xlsx', 'xls']" :file-size="10" :limit="5" :uploadFileUrl=importUrl
        @update:modelValue="handleFileUpload">
      </file-upload>
    </wms-form>

    <wms-table :loading="loading" :data-list="ibMasterList" :column="column" :pageInfo="queryParams" @get-list="getList"
      @row-click="handleRowClick" />

    <ib-detail v-if="showDetail" v-model="showDetail" :master-info="masterInfo" />

  </div>
</template>

<script setup name="IbMasterNoProd">
import WmsTable from '@/components/WmsTable/index.vue'
import WmsForm from '@/components/WmsForm/index.vue'
import IbDetail from '../ibDetails/index.vue'
import { listIbMaster, getIbMaster, delIbMaster, addIbMaster, updateIbMaster } from "@/api/wms/ibMaster";
import { data, column, formList } from './index.js'
import FileUpload from '@/components/FileUpload/index.vue'
import { ref, reactive, getCurrentInstance, onMounted } from "vue";

const { proxy } = getCurrentInstance();
const queryParams = reactive(data.queryParams);
const ibMasterList = ref([]);
let loading = ref(true);
let showDetail = ref(false);
const importUrl = ref('/wms/ibMaster/wip/import')

// 文件列表
const fileList = ref([])

// 子菜单传输参数
let masterInfo = reactive({
  ibMasterId: null,
  ibMasterNo: null
})

/** 查询入库主单列表 */
function getList() {
  loading.value = true;
  // 添加过滤条件
  queryParams.ibMasterType = 'PO_IN_WIP';
  listIbMaster(proxy.addDateRange(queryParams, queryParams.dateRange)).then(response => {
    ibMasterList.value = response.rows;
    queryParams.total = response.total;
    loading.value = false;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  //将页面的时间选择器数据beginTime和endTime清空
  queryParams.dateRange = null;
  handleQuery();
}

/** 文件上传成功 */
function handleFileUpload(fileList) {
  console.log('上传文件', fileList);
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('wms/ibMaster/export', {
    ...queryParams
  }, `原料入库单_${new Date().getTime()}.xlsx`)
}

const handleRowClick = (row) => {
  showDetail.value = true
  masterInfo.ibMasterId = row.ibMasterId
  masterInfo.ibMasterNo = row.ibMasterNo
}

getList();
</script>
